home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / tuwtcpsr / netdb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-28  |  1.6 KB  |  79 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <netdb.h>
  4.  
  5.  
  6. int atoet(char *a,char *et)
  7. {
  8.   int etbuf[6];
  9.   if(sscanf(a,"%2x:%2x:%2x:%2x:%2x:%2x",&etbuf[0],&etbuf[1],&etbuf[2],&etbuf[3],&etbuf[4],&etbuf[5]) == 6)
  10.   {
  11.     et[0] = (char)etbuf[0];
  12.     et[1] = (char)etbuf[1];
  13.     et[2] = (char)etbuf[2];
  14.     et[3] = (char)etbuf[3];
  15.     et[4] = (char)etbuf[4];
  16.     et[5] = (char)etbuf[5];
  17.     return(6);
  18.   }    
  19.   return(0);
  20. }
  21.  
  22. long atoin(char *a)
  23. {
  24. unsigned  n1,n2,n3,n4;
  25.  
  26.  
  27.   if(sscanf(a,"%u.%u.%u.%u",&n1,&n2,&n3,&n4) == 4)
  28.     return(((unsigned long)n1<<24) + ((unsigned long)n2<<16) + ((unsigned long)n3<<8) +(unsigned long)n4);
  29.   return(0L);
  30. }
  31.  
  32. #ifdef __GETHOSTBYNAME
  33. long gethostbyname(char *host)
  34. {
  35.   register FILE *fp;
  36.   register long inet = 0L;
  37.   register char *p; 
  38.   char buf[128];
  39.  
  40.  
  41.   if(strchr(host,'.'))
  42.   {
  43.     inet = atoin(host);
  44.   }
  45.   if(inet==0L)
  46.   {
  47.     p = (char *)getnetenv("HOSTS");
  48.     if(p) strcpy(buf,p);
  49.     else buf[0]=0;
  50.     if(!p || p[strlen(p)-1] == '\\') strcat(buf,"hosts");
  51.     if((fp=fopen(buf,"r")) == NULL)
  52.     {
  53.       inet=0L;
  54.     }
  55.     else
  56.     {
  57.       while (!feof(fp))
  58.       {
  59.         fgets(buf,(int)sizeof(buf),fp);
  60.         p=strtok(buf," \t");
  61.         if(!p || *p=='#' || *p=='\n') continue;
  62.         if((inet = atoin(p)) != 0L)
  63.           do
  64.           {
  65.             p=strtok(NULL," \t\n");
  66.             if(p && !strcmp(p,host))
  67.             {
  68.               fclose(fp);
  69.               return(inet);
  70.             }
  71.           }while(p);
  72.       }
  73.       fclose(fp);
  74.       inet = 0L;         
  75.     }
  76.   }
  77.   return(inet);
  78. }
  79. #endif